﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;

namespace YouHP.Pages
{
    public class ListTreatments : BasePage
    {
        protected List<TreatmentInfo> mTreatmentLst;
        protected List<TreatmentTypeInfo> mTreatmentTypeLst;
        protected int _pageCount = 0;
        protected int _TreatmentCount = 0;
        protected int _pageSize = 2;
        protected int _pageIndex = 1;
        protected int _firstpage = 1;
        protected int _prevpage;
        protected int _nextpage;
        protected int UsedPatientCount = 50;
        protected string url = "ListTreatments.aspx?";


        protected static List<string> mPingYin = new List<string>();

        static ListTreatments()
        {
            for (char c = 'A'; c <= 'Z'; c++)
            {
                mPingYin.Add(c.ToString());
            }
        }



        protected override void ShowPage()
        {
            //SeoTitle = "分享";
            PageTitle = "治疗列表";

            mTreatmentTypeLst = TreatmentBLL.Instance.GetTreatmentTypeList();


            //当前页

            _pageIndex = RequestTools.GetQueryInt("page", 1);

            //页面跳转
            int pagesel = RequestTools.GetFormInt("pagesel", 0);
            if (pagesel != 0) _pageIndex = pagesel;


            mTreatmentLst = TreatmentList();


            //分页计算
            _pageCount = _TreatmentCount / _pageSize;

            if (_TreatmentCount / _pageSize == 0) _pageCount++;

            else if (_TreatmentCount % _pageSize != 0) _pageCount++;

            //前后翻页计算
            _prevpage = _pageIndex - 1;
            if (_prevpage == 0) _prevpage++;

            _nextpage = _pageIndex + 1;
            if (_nextpage > _pageCount) _nextpage = _pageCount;

        }


        public List<TreatmentInfo> TreatmentList()
        {
            //搜索治疗

            string sname = RequestTools.GetQueryString("Treatmentname");
            if (sname != "")
            {
                mTreatmentLst = TreatmentBLL.Instance.GetTreatmentByName(_pageSize, _pageIndex, sname, out _TreatmentCount);
                url = url + "Treatmentname=" + sname;
                if (mTreatmentLst.Count == 0)
                    this.AddErrLine("请输入正确的症状名称");
                return mTreatmentLst;
            }


            //拼音首字母排列

            string pinyin = RequestTools.GetQueryString("PinYin");
            if (!pinyin.Equals(""))
            {

                url = url + "PinYin=" + pinyin;
                mTreatmentLst = TreatmentBLL.Instance.GetTreatmentByPinYin(_pageSize, _pageIndex, pinyin, out _TreatmentCount);
                return mTreatmentLst;
            }
            //治疗类型排序

            int TreatmentType = RequestTools.GetQueryInt("TreatmentTypeId", -1);

            if (TreatmentType != -1)
            {
                url = url + "TreatmentTypeId=" + TreatmentType;
                mTreatmentLst = TreatmentBLL.Instance.GetTreatmentByType(_pageSize, _pageIndex, TreatmentType, out _TreatmentCount);
                return mTreatmentLst;
            }

            else
            {
                mTreatmentLst = TreatmentBLL.Instance.GetTreatmentList(_pageSize, _pageIndex, out _TreatmentCount);

                return mTreatmentLst;

            }


        }

    }
}
